/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-10-10 21:06:30
 * @LastEditTime: 2019-10-31 17:32:43
 * @LastEditors: Please set LastEditors
 */
// 引入css资源
require('./assets/sass/common.scss')

// require('./assets/sass/element-variables.scss')
/* variable-sass */

// 引入第三方库和插件
import Vue from 'vue'
import VueRouter from 'vue-router'
import Vuex from 'vuex'
import App from './App.vue'
import ElementUI, { Message } from 'element-ui'
import VueLazyload from 'vue-lazyload'
import store from './store/index.js'

import 'codemirror/lib/codemirror.css'
import 'tui-editor/dist/tui-editor.css'
import 'tui-editor/dist/tui-editor-contents.css'
import 'highlight.js/styles/github.css'

import '../static/Ueditor/ueditor.config.js'
import '../static/Ueditor/ueditor.all.min.js'
import '../static/Ueditor/lang/zh-cn/zh-cn.js'
import '../static/Ueditor/ueditor.parse.min.js'
import '../static/ueditor/themes/default/css/ueditor.css'

const { ENVIRONMENT } = require('./app.environment')
if (ENVIRONMENT === 'development') {
  require('element-ui/lib/theme-chalk/index.css')
}
// 按需引入element-ui
// import { Button, Select } from 'element-ui';
// Vue.component(Button.name, Button);
// Vue.component(Select.name, Select);
/* 或写为
 * Vue.use(Button)
 * Vue.use(Select)
 */

// 引入utils工具

import { getLocalStroage, setLocalStroage, clearAllLocalStroage } from './utils/stroage'

// import { isEmpty } from './utils/isEmpty';
import environment from './utils/getEnvironment'

import axios from './utils/http'

// 引入路由
import routes from './routers/main.routes'

// 设置环境信息
// clearAllLocalStroage();
setLocalStroage('environment', JSON.stringify(environment))
// setLocalStroage('isLogin', "false")

const router = new VueRouter({
  routes // (缩写) 相当于 routes: routes
})

// 全局路由守卫
router.beforeEach((to, from, next) => {
  if(to.path == '/login' || to.path == '/register' || to.path == '/index'){
  next()
  } else{
    if(getLocalStroage('isLogin') == "true"){
      next();
    }else{
      Message.error('权限验证失败，请重新登陆');
      next('/login');
    }
  }
})

// 将axios注入到vue原型上
// Vue.prototype.$axios = axios;

// 使用插件
Vue.use(axios)
Vue.use(VueRouter)
Vue.use(ElementUI)
// Vue.use(VueLazyload)
Vue.use(VueLazyload, {
  preLoad: 1.0,
  error: require('./assets/images/404.jpg'),
  loading: require('./assets/images/loading.gif'),
  attempt: 1
})

/* eslint-disable no-new */
const app =new Vue({
  el:'#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
